package com.yeyks.consumer.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.yeyks.consumer.dal.domain.MemberCardDetail;
import com.yeyks.consumer.dal.dao.MemberCardDetailMapper;
import com.yeyks.consumer.param.UserMemberCard.UserMemberCardDetailListParam;
import com.yeyks.consumer.service.MemberCardDetailService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;


/**
 * <p>
 * 余额明细 服务实现类
 * </p>
 *
 * @author yun
 * @since 2019-06-25
 */
@Service
public class MemberCardDetailServiceImpl extends ServiceImpl<MemberCardDetailMapper, MemberCardDetail> implements MemberCardDetailService {

    /**
     * 创建余额详情
     *
     * @param detail
     * @return
     */
    @Override
    public Integer insert(MemberCardDetail detail) {
        detail.setCreateTime(new Date());
        return baseMapper.insert(detail);
    }

    /**
     * 分页获取详情
     *
     * @param loginUser
     * @param pageNo
     * @param pageSize
     * @return
     */
    @Override
    public List<MemberCardDetail> list(UserMemberCardDetailListParam param) {
        PageHelper.startPage(param.getPageNo(),param.getPageSize());
        List<MemberCardDetail> memberCardDetails = baseMapper.selectList(
                new QueryWrapper<MemberCardDetail>()
                        .eq(MemberCardDetail.USER_ID, param.getUserId())
                        .eq(MemberCardDetail.CARD_TYPE, param.getCardType())
                        .orderByDesc(MemberCardDetail.CREATE_TIME)
        );
        return memberCardDetails;
    }


}
